<extend name="Public/base" />

<block name="body">
	<!-- 标题栏 -->
	<div class="main-title">
		<h2>钩子列表</h2>
	</div>
	<div class="cf">
		<?php if (is_administrator()): ?>
			<a class="btn" href="{:U('addhook')}">新 增</a>
		<?php endif ?>
	</div>

	<!-- 数据列表 -->
	<div class="data-table table-striped">
		{$_table_list}
	</div>
	<!-- 分页 -->
    <div class="page">
        {$_page}
    </div>
</block>

<block name="script">
	<script type="text/javascript" src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>

	<!-- 弹出层模板 -->
	<script id="hooktpl" type="text/tpl">
		<form action="{:U('updateSort')}" method="post" class="form-horizontal hooktpl">
			<label class="item-label">插件名称</label>
			<div class="controls">
				<label class="textarea">
					<textarea name="addons"></textarea>
				</label>
				<input type="hidden" name="id" value="">
				<span class="check-tips">多个插件用','分开</span>
			</div>
		</form>
	</script>

	<script type="text/javascript">
		$(function(){
			$('a.editAddons').click(function(){
				var value = $.trim(this.title);
				var html = $($("#hooktpl").html());
				html.find("textarea").val(value);
				html.find("input:hidden").val(this.id);

				//ajaxForm 公共函数
		        function ajaxForm(element,callback,dataType){
		            var form = $(element).closest('form');
		            var dataType = dataType || 'json';
		            $.ajax({
		                type: "POST",
		                url: form.attr('action'),
		                data: form.serialize(),
		                async: false,
		                dataType:dataType,
		                success: function(data) {
		                    if($.isFunction(callback)){
		                        callback(data,form);
		                    }
		                }
		            });
		        }

				option = {
					title:'编辑钩子处的插件',
					actions:['close'],
					drag:true,
					tools:true,
					buttons:{"ok":['保存', 'blue',function(){
						var _this = this;
						ajaxForm(this.find('.textarea'),function(data){
							if (data.status){
				                $.thinkbox.success(data.info,{
				                    afterHide:function(){
				                        _this.hide();
				                        setTimeout(function(){
				                        	location.reload(true);
				                        },500);
				                    }
				                });
				            }else{
				                $.thinkbox.error(data.info);
				            }
						})
					}]}
				}
				$.thinkbox(html,option);
			});
		})
	</script>
</block>